package com.sinopec.basemodule.utils;

import android.text.InputType;
import android.text.method.DigitsKeyListener;
import android.view.View;
import android.widget.EditText;

import com.sinopec.basemodule.annotation.Visibility;

public class ViewUtils {
    public static void moveToEndSelection(EditText view) {
        view.setSelection(view.getText() != null ? view.getText().length() : 0);
    }

    /**
     * 只能输出英文和数字的键盘
     *
     * @param et
     */
    public static void acceptedChar(EditText et) {
        et.setKeyListener(new DigitsKeyListener() {
            @Override
            public int getInputType() {

                return InputType.TYPE_TEXT_VARIATION_PASSWORD;
            }

            @Override
            protected char[] getAcceptedChars() {
                String dataID = "qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM1234567890";
                //char[] data = getStringData(R.string.login_only_can_input).toCharArray();
                char[] data = dataID.toCharArray();
                return data;
            }

        });
    }

    /**
     * view的显示是否等同于判断的
     */
    public static boolean isEqualsVisibility(View view, @Visibility int visibility) {
        int viewVisibility = view.getVisibility();
        return viewVisibility == visibility;
    }

    /**
     * 设置view的显示模式
     */
    public static void setVisibility(View view, @Visibility int visibility) {
        if (!isEqualsVisibility(view, visibility)) {
            view.setVisibility(visibility);
        }
    }
}
